package Lee_code;

public class Lee_714_2 {
    public int maxProfit(int[] prices, int fee) {
        int len = prices.length;
        // dp数组, 0是持有股票, 1是不持有股票
        int[][] dp = new int[len][2];
        dp[0][0] = -prices[0];
        dp[0][1] = 0;
        for (int i=1; i<len; i++){
            dp[i][0] = Math.max(dp[i-1][0], dp[i-1][1]-prices[i]);
            dp[i][1] = Math.max(dp[i-1][0]+prices[i]-fee, dp[i-1][1]);
        }
        return dp[len-1][1];
    }
}
